#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>

typedef int ElemType;
typedef struct DNode{
    ElemType data;
    struct DNode *next, *prior;
}DNode, *DLinkList;

bool initList(DLinkList L);
bool insertList(DLinkList L, int index, ElemType elem);

int main(){
    DLinkList L;
    initList(L);
    insertList(L, 1, 10);
    insertList(L, 2, 100);
    printf("%d\n", L->next->data);
    printf("%d\n", L->next->next->data);
    return 0;
}

bool initList(DLinkList L){
    L = (DNode *)malloc(sizeof(DNode));
    if(L==NULL) return false;
    L->next = NULL;
    L->prior = NULL;
    return true;
}

bool insertList(DLinkList L, int index, ElemType elem){
    if(index<1||L==NULL) return false;
    DNode *p = L;
    int id = 0;
    while(p!=NULL&&id<index-1){
        p = p->next;
        id++;
    }
    DNode *temp = (DNode *)malloc(sizeof(DNode));
    if(temp==NULL) return false;
    temp->data = elem;
    temp->next = p->next;
    if(p->next!=NULL){
        p->next->prior = temp;
    }
    p->next = temp;
    temp->prior = p;
    return true;
}